package main

import (
	"github.com/gin-gonic/gin"
	"io"
	"os"
	"time"
)

type Person struct {
	Name string `form:"name"`
	Address string `form:"address"`
	Birthday time.Time `form:"birthday" time_format:"2006-01-02"`
}

func main(){
	f, _ := os.Create("gin.log")
	gin.DefaultWriter = io.MultiWriter(f)
	gin.DefaultErrorWriter = io.MultiWriter(f)
	r := gin.New()
	// gom Logger 为打印log的中间件，打印 链接信息 状态码 时延
	// gin recovery 即使发生 panic 框架也不会挂
	r.Use(gin.Logger(), gin.Recovery())
	r.GET("/testing", testing)
	r.Run()
}

func testing (c *gin.Context) {
	var person Person
	if err:=c.ShouldBind(&person); err == nil {
		c.String(200, "%v", person)
	} else {
		c.String(200, "person bind error: %v", err)
	}
}